const cloud = require('wx-server-sdk');
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });
const db = cloud.database();

// 获取所有数据
const MAX_LIMIT = 100
exports.main = async (event, context) => {

  const res = await db.collection('user').where({
    openId: event.openId
  }).get()
  return res
  // const countResult = await db.collection('goodList').count()
  // const total = countResult.total
  // const batchTimes = Math.ceil(total / 100)
  // const tasks = []
  // for (let i = 0; i < batchTimes; i++) {
  //   const promise = db.collection('goodList').skip(i * MAX_LIMIT).limit(MAX_LIMIT).get()
  //   tasks.push(promise)
  // }
  // return (await Promise.all(tasks)).reduce((acc, cur) => {
  //   return {
  //     data: acc.data.concat(cur.data),
  //     errMsg: acc.errMsg,
  //   }
  // })
}